﻿using System;

namespace HslCommunication.Algorithms.PID
{
	/// <summary>
	/// 一个PID的辅助类，可以设置 P,I,D 三者的值，用来模拟信号波动的时候，信号的收敛情况
	/// </summary>
	// Token: 0x020001A5 RID: 421
	public class PIDHelper
	{
		/// <summary>
		/// 实例化一个默认的对象
		/// </summary>
		// Token: 0x06002140 RID: 8512 RVA: 0x000A19CC File Offset: 0x0009FBCC
		public PIDHelper()
		{
			this.PidInit();
		}

		/// <summary>
		/// 初始化PID的数据信息
		/// </summary>
		// Token: 0x06002141 RID: 8513 RVA: 0x000A19E0 File Offset: 0x0009FBE0
		private void PidInit()
		{
			this.prakp = 0.0;
			this.praki = 0.0;
			this.prakd = 0.0;
			this.prvalue = 0.0;
			this.err = 0.0;
			this.err_last = 0.0;
			this.err_next = 0.0;
			this.MAXLIM = double.MaxValue;
			this.MINLIM = double.MinValue;
			this.UMAX = 310;
			this.UMIN = -100;
			this.deadband = 2.0;
		}

		/// <summary>
		/// -rando
		/// 比例的参数信息
		/// </summary>
		// Token: 0x170006CB RID: 1739
		// (get) Token: 0x06002143 RID: 8515 RVA: 0x000A1AA0 File Offset: 0x0009FCA0
		// (set) Token: 0x06002142 RID: 8514 RVA: 0x000A1A97 File Offset: 0x0009FC97
		public double Kp
		{
			get
			{
				return this.prakp;
			}
			set
			{
				this.prakp = value;
			}
		}

		/// <summary>
		/// 积分的参数信息
		/// </summary>
		// Token: 0x170006CC RID: 1740
		// (get) Token: 0x06002145 RID: 8517 RVA: 0x000A1AB1 File Offset: 0x0009FCB1
		// (set) Token: 0x06002144 RID: 8516 RVA: 0x000A1AA8 File Offset: 0x0009FCA8
		public double Ki
		{
			get
			{
				return this.praki;
			}
			set
			{
				this.praki = value;
			}
		}

		/// <summary>
		/// 微分的参数信息
		/// </summary>
		// Token: 0x170006CD RID: 1741
		// (get) Token: 0x06002147 RID: 8519 RVA: 0x000A1AC2 File Offset: 0x0009FCC2
		// (set) Token: 0x06002146 RID: 8518 RVA: 0x000A1AB9 File Offset: 0x0009FCB9
		public double Kd
		{
			get
			{
				return this.prakd;
			}
			set
			{
				this.prakd = value;
			}
		}

		/// <summary>
		/// 获取或设置死区的值
		/// </summary>
		// Token: 0x170006CE RID: 1742
		// (get) Token: 0x06002149 RID: 8521 RVA: 0x000A1AD3 File Offset: 0x0009FCD3
		// (set) Token: 0x06002148 RID: 8520 RVA: 0x000A1ACA File Offset: 0x0009FCCA
		public double DeadBand
		{
			get
			{
				return this.deadband;
			}
			set
			{
				this.deadband = value;
			}
		}

		/// <summary>
		/// 获取或设置输出的上限，默认为没有设置
		/// </summary>
		// Token: 0x170006CF RID: 1743
		// (get) Token: 0x0600214B RID: 8523 RVA: 0x000A1AE4 File Offset: 0x0009FCE4
		// (set) Token: 0x0600214A RID: 8522 RVA: 0x000A1ADB File Offset: 0x0009FCDB
		public double MaxLimit
		{
			get
			{
				return this.MAXLIM;
			}
			set
			{
				this.MAXLIM = value;
			}
		}

		/// <summary>
		/// 获取或设置输出的下限，默认为没有设置
		/// </summary>
		// Token: 0x170006D0 RID: 1744
		// (get) Token: 0x0600214D RID: 8525 RVA: 0x000A1AF5 File Offset: 0x0009FCF5
		// (set) Token: 0x0600214C RID: 8524 RVA: 0x000A1AEC File Offset: 0x0009FCEC
		public double MinLimit
		{
			get
			{
				return this.MINLIM;
			}
			set
			{
				this.MINLIM = value;
			}
		}

		/// <summary>
		/// 获取或设置当前设置的值
		/// </summary>
		// Token: 0x170006D1 RID: 1745
		// (get) Token: 0x0600214F RID: 8527 RVA: 0x000A1B06 File Offset: 0x0009FD06
		// (set) Token: 0x0600214E RID: 8526 RVA: 0x000A1AFD File Offset: 0x0009FCFD
		public double SetValue
		{
			get
			{
				return this.setValue;
			}
			set
			{
				this.setValue = value;
			}
		}

		/// <summary>
		/// 计算Pid数据的值
		/// </summary>
		/// <returns>计算值</returns>
		// Token: 0x06002150 RID: 8528 RVA: 0x000A1B10 File Offset: 0x0009FD10
		public double PidCalculate()
		{
			this.err_next = this.err_last;
			this.err_last = this.err;
			this.err = this.SetValue - this.prvalue;
			this.prvalue += this.prakp * (this.err - this.err_last + this.praki * this.err + this.prakd * (this.err - 2.0 * this.err_last + this.err_next));
			bool flag = this.prvalue > this.MAXLIM;
			if (flag)
			{
				this.prvalue = this.MAXLIM;
			}
			bool flag2 = this.prvalue < this.MINLIM;
			if (flag2)
			{
				this.prvalue = this.MINLIM;
			}
			return this.prvalue;
		}

		// Token: 0x040007F3 RID: 2035
		private double prakp;

		// Token: 0x040007F4 RID: 2036
		private double praki;

		// Token: 0x040007F5 RID: 2037
		private double prakd;

		// Token: 0x040007F6 RID: 2038
		private double prvalue;

		// Token: 0x040007F7 RID: 2039
		private double err;

		// Token: 0x040007F8 RID: 2040
		private double err_last;

		// Token: 0x040007F9 RID: 2041
		private double err_next;

		// Token: 0x040007FA RID: 2042
		private double setValue;

		// Token: 0x040007FB RID: 2043
		private double deadband;

		// Token: 0x040007FC RID: 2044
		private double MAXLIM;

		// Token: 0x040007FD RID: 2045
		private double MINLIM;

		// Token: 0x040007FE RID: 2046
		private int index;

		// Token: 0x040007FF RID: 2047
		private int UMAX;

		// Token: 0x04000800 RID: 2048
		private int UMIN;
	}
}
